<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body class="container">
    <div class="row">
        <ol class="breadcrumb">
            <li><a href="javascript:void(0)">问卷管理</a></li>
            <li class="active">问卷提交数据列表</li>
        </ol>
    </div>
    <div class="row">
        <form class="form-inline">
            <div class="form-group">
                <label for="paperName">时间范围</label>
                <input type="text" class="form-control" name="startTime" id="startTime" placeholder="开始时间">
                ~
                <input type="text" class="form-control" name="endTime" id="endTime" placeholder="结束时间">
            </div>
            <button id="searchBtn" type="button" class="btn btn-default"><span class="glyphicon glyphicon-search"></span></button>
        </form>
    </div>
    <div class="row">
        <!-- 答案列表 -->
        <table id="answerList" class="table">

        </table>

        <div id="opBar">
            <a onclick="detail(this)" href="javascript:void(0)">查看</a> / 
            <a onclick="deleteData(this)" href="javascript:void(0)">删除</a> /
        </div>
    </div>
    <div class="row">
        <nav id="pageBar" aria-label="Page navigation">
            <ul class="pagination">
                <li>
                <a href="#" aria-label="Previous">
                    <span aria-hidden="true">&laquo;</span>
                </a>
                </li>
                <li><a href="#">1</a></li>
                <li><a href="#">2</a></li>
                <li><a href="#">3</a></li>
                <li><a href="#">4</a></li>
                <li><a href="#">5</a></li>
                <li>
                <a href="#" aria-label="Next">
                    <span aria-hidden="true">&raquo;</span>
                </a>
                </li>
            </ul>
        </nav>
    </div>



    <script>
        // 查询所有的域
        var getFieldsUlr = "http://localhost:8080/paper/field/queryByPaperId";
        var answerListUrl = "http://localhost:8080/paper/answerList"

        // 要有paperId,这里使用的是answerListPaperId
        //加载所有的域，动态生成columns
        $.ajax({
            type:"GET",
            url:getFieldsUlr,
            data:{paperId:answerListPaperId},
            async:false,
            success:function(res){
                if(res.code==200 && res.data){
                    var fields = res.data;
                    var columns = [];
                    $.each(fields,function(index,item){
                        //根据域，个数组添加列
                        var col = {"title":item.fieldName};
                        switch(item.fieldType){
                            case 2:
                                col['field']="text_"+item.fieldId;
                                break;
                            case 3:
                                col['field']="textarea_"+item.fieldId;
                                col.formatter=function(value){
                                    return value.length > 5 ?(value.substring(0,5)+"..."):value;
                                }
                                break;
                            case 4:
                                col['field']="radio_"+item.fieldId;
                                break;
                            case 5:
                                col['field']="checkbox_"+item.fieldId;
                                col.formatter=function(value){
                                    return value.length > 5 ?(value.substring(0,5)+"..."):value;
                                }
                                break;
                        }
                        //将列加入到columns中
                        columns.push(col);
                    });
                    //最后添加一个操作栏
                    columns.push({field:"st9527-options",title:"操作",barId:'opBar'});
                    // 列说明已经准备好，就可以直接生成数据列表
                    st9527.table("answerList",columns,answerListUrl,{page:1,size:10,paperId:answerListPaperId},"pageBar");
                }
            }
        });
        </script>
    </script>
</body>
</html>